package net.linku.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import net.linku.annotation.AutoResponse;
import net.linku.model.req.privilege.AdminPrivilegeQuery;
import net.linku.model.req.privilege.AdminPrivilegeReq;
import net.linku.model.req.privilege.AdminStatusChangeReq;
import net.linku.model.resp.login.LAPrivilegeVO;
import net.linku.service.LAPrivilegeService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

/**
 * 后台权限管理控制器
 */
@RestController
@AutoResponse
@RequiredArgsConstructor
@RequestMapping("/privilege")
@Api(tags = "后台权限管理控制器")
public class AdminPrivilegeController {

    private final LAPrivilegeService privilegeService;

    @PostMapping("/list")
    @ApiOperation(value = "分页查询权限列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "current", value = "当前页", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "page", value = "页码", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "size", value = "每页大小", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "query", value = "查询条件", required = true, dataType = "AdminPrivilegeQuery", paramType = "body")
    })
    public Page<LAPrivilegeVO> pagePrivilege(@Validated @ApiIgnore @RequestBody AdminPrivilegeQuery query) {
        return privilegeService.pagePrivilege(query);
    }

    @PostMapping("/add")
    @ApiOperation(value = "添加权限")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "privilegeReq", value = "权限请求对象", required = true, dataType = "AdminPrivilegeReq", paramType = "body")
    })
    public Boolean addPrivilege(@RequestBody @Validated AdminPrivilegeReq privilegeReq) {
        return privilegeService.addPrivilege(privilegeReq);
    }

    @PostMapping("/update")
    @ApiOperation(value = "更新权限")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "privilegeReq", value = "权限请求对象", required = true, dataType = "AdminPrivilegeReq", paramType = "body")
    })
    public Boolean updatePrivilege(@RequestBody @Validated AdminPrivilegeReq privilegeReq) {
        return privilegeService.updatePrivilege(privilegeReq);
    }

    @PostMapping("/delete")
    @ApiOperation(value = "删除权限")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "statusChangeReq", value = "权限状态变更请求对象", required = true, dataType = "AdminPrivilegeStatusChangeReq", paramType = "body")
    })
    public Boolean deletePrivilege(@RequestBody @Validated AdminStatusChangeReq statusChangeReq) {
        return privilegeService.deletePrivilege(statusChangeReq);
    }
}
